#pragma once
#include "afxwin.h"
#include "ProgressBarDialog.h"

//defines
#define DEALER_LOAD   "\\dealer.ini"
#define DEALER_SAVE   "\\dealer.ini"

//Key names in sections
#define KN_BUY_SPEED      _T("buy_speed")
#define KN_SELL_COST      _T("sell_cost")
#define KN_NPC            _T("npc")
#define KN_TYPE           _T("type")
#define KN_CASH           _T("cash")
#define KN_ONLY_USED      _T("onlyuseditems")
#define KN_GIVES_CHANGE   _T("giveschange")
#define KN_ACCEPT_GIFTS   _T("acceptsgifts")
#define KN_SOME_USED      _T("someuseditems")
#define KN_HAS_NO_INV     _T("hasnoinventory")
#define KN_ITEM           _T("item")
#define KN_MAX            _T("max")
//Key default values
#define KDF_BUY_SPEED      100
#define KDF_SELL_COST      100
#define KDF_NPC            0
#define KDF_TYPE           0
#define KDF_CASH           0
#define KDF_ONLY_USED      0
#define KDF_GIVES_CHANGE   0
#define KDF_ACCEPT_GIFTS   0
#define KDF_SOME_USED      0
#define KDF_HAS_NO_INV     0
#define KDF_ITEM           0
#define KDF_MAX            0


// CDealerDlg dialog
// THIS STRUCTURE HAS UNCHANGING INFO THAT DOESN'T GET SAVED/RESTORED/RESET

enum
	{
	ARMS_DEALER_TONY,
	ARMS_DEALER_FRANZ,
	ARMS_DEALER_KEITH,
	ARMS_DEALER_JAKE,
	ARMS_DEALER_GABBY,

	ARMS_DEALER_DEVIN,
	ARMS_DEALER_HOWARD,
	ARMS_DEALER_SAM,
	ARMS_DEALER_FRANK,

	ARMS_DEALER_BAR_BRO_1,
	ARMS_DEALER_BAR_BRO_2,
	ARMS_DEALER_BAR_BRO_3,
	ARMS_DEALER_BAR_BRO_4,

	ARMS_DEALER_MICKY,

	ARMS_DEALER_ARNIE,
	ARMS_DEALER_FREDO,
	ARMS_DEALER_PERKO,

	// added only in GameVersion 54
	ARMS_DEALER_ELGIN,

	// added only in GameVersion 55
	ARMS_DEALER_MANNY,

	NUM_ARMS_DEALERS,
};

typedef struct
{
	union
	{
		struct
		{
			int		dBuyModifier;				// The price modifier used when this dealer is BUYING something.
			int		dSellModifier;			// The price modifier used when this dealer is SELLING something.
		};
		struct
		{
			int		dRepairSpeed;				// Modifier to the speed at which a repairman repairs things
			int		dRepairCost;				// Modifier to the price a repairman charges for repairs
		};
	};

	UINT8		ubShopKeeperID;					// Merc Id for the dealer
	UINT8		ubTypeOfArmsDealer;			// Whether he buys/sells, sells, buys, or repairs
	INT32		iInitialCash;						// How much cash dealer starts with (we now reset to this amount once / day)
	UINT32	uiFlags;								// various flags which control the dealer's operations
} ARMS_DEALER_INFO;

typedef struct
{
	INT16		sItemIndex;
	UINT8		ubOptimalNumber;
} DEALER_POSSIBLE_INV;

class CWeaponDlg;

class CDealerDlg : public CDialog
{
	DECLARE_DYNAMIC(CDealerDlg)

public:
	CDealerDlg(CWnd* pParent = NULL);   // standard constructor
	virtual ~CDealerDlg();

	static const unsigned int MAXITEMS				= 2048;

	ARMS_DEALER_INFO	ArmsDealerInfo[ NUM_ARMS_DEALERS ];
	UINT32 gDealerInvCount[NUM_ARMS_DEALERS];
	DEALER_POSSIBLE_INV gDealerInventory[NUM_ARMS_DEALERS][MAXITEMS];

// Dialog Data
	enum { IDD = IDD_DEALERDLG };

protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support

	virtual BOOL OnInitDialog();

	DECLARE_MESSAGE_MAP()
private:
  bool m_bSaved;
  COXToolTipCtrl m_tooltip;
public:
  bool IsSaved() const { return m_bSaved; }

	void OnOK();
	void OnCancel();
	
	void Load( CProgressBarDialog *pProgressDialog );
	void Save(void);
	
	
	int   m_nMax;
	int   m_iBuyPercent;
	int   m_iSellPercent;
	int   m_DailyCash;
	BOOL  m_bUsedOnly;
	BOOL  m_bGivesChange;
	BOOL  m_bAcceptsGifts;
	BOOL  m_bHasSomeUsed;
	BOOL  m_bHasNoInventory;
		
	CListBox m_lbDealerNames;
	CListBox m_lbItems;
  CComboBox m_cbNPCName;
	CComboBox m_cbItemName;
  CComboBox m_cbType;

  CWeaponDlg * m_pWeaponDlg;
  CItemsDlg * m_pItemsDlg;

  void SetClassPointers(ClassPointers *p);

  afx_msg void OnLbnSelchangeListDealerNames();
	afx_msg void OnLbnSelchangeListDealerInventory();
  afx_msg void OnCbnSelchangeItemname();
	afx_msg void OnEnChangeEditItemNumber();
	afx_msg void OnCbnSelchangeComboNpcName();
	afx_msg void OnEnChangeEditBuyModifier();
	afx_msg void OnEnChangeEditSellModifier();
	afx_msg void OnEnChangeEditInitCash();
  afx_msg void OnBnClickedCheckUsedOnly();
  afx_msg void OnBnClickedCheckGivesChange();
  afx_msg void OnBnClickedCheckAcceptGifts();
  afx_msg void OnBnClickedCheckSomeUsedItems();
  afx_msg void OnBnClickedCheckNoInventory();
  afx_msg void OnCbnSelchangeComboDealerType();
  BOOL PreTranslateMessage(MSG* pMsg) 
  {
    if(pMsg->message >= WM_MOUSEFIRST && pMsg->message <= WM_MOUSELAST)
      m_tooltip.RelayEvent(pMsg);

    return CDialog::PreTranslateMessage(pMsg);
  }
};
